<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户管理</title>
  <link href="../../css/style.css" rel="stylesheet" type="text/css" />
  <!--axios-->
  <script type="text/javascript" src="../../js/axios.js"></script>
  <script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
  <script type="text/javascript" src="../../js/api.js"></script>
  <link rel="stylesheet" href="../../layui/css/layui.css">
  <script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript">
function deltipOpen(orderId,currentpage,rows) {
	$("#deltip").fadeIn(200);
    $("#delOrder").click(function (){
      var url="http://121.37.227.40:8000/"
      axios({
        url:url+'marketing/delOrder/',
        method:"POST",
        data:{
        },
        params:{
          orderId:orderId
        },
        dataType:"JSON"
      }).then(function (){
        var or=$("#orderId").val();
        var cu=$("#customName").val();
        var st=$("#startTime").val();
        var en=$("#endTime").val();
        var mi=$("#minMoney").val();
        var ma=$("#maxMoney").val();
        var sta=$("#status").val();
        deltipClose()
        load(currentpage,rows,or,cu,st,en,mi,ma,sta)
        layui.use('layer', function(){
          var layer = layui.layer;
          layer.msg("删除成功",{icon:1})
        });
      })
    })
}
function deltipClose() {
	$("#deltip").fadeOut(200);
}
function examinetipOpen(orderId,currentpage,rows) {
	$("#examinetip").fadeIn(200);
  $("#subexamine").click(function () {
    var dept=$("#dept").val()
    var post=$("#post").val()
    var uid=$("#name").val()
    if (dept==0||post==0||uid==0){
      layui.use('layer', function(){
        var layer = layui.layer;
        layer.msg("请选择",{icon:5})
      });
    }else {
    var url = "http://121.37.227.40:8000/"
    axios({
      url: url + 'marketing/orderExamine/',
      method: "POST",
      data: {},
      params: {
        orderId: orderId,
        checkId:uid
      },
      dataType: "JSON"
    }).then(function (){
      var or=$("#orderId").val();
      var cu=$("#customName").val();
      var st=$("#startTime").val();
      var en=$("#endTime").val();
      var mi=$("#minMoney").val();
      var ma=$("#maxMoney").val();
      var sta=$("#status").val();
      examinetipclose()
      load(currentpage,rows,or,cu,st,en,mi,ma,sta)
      layui.use('layer', function(){
        var layer = layui.layer;
        layer.msg("提交审核成功",{icon:1})
      });
    })
    }
  })
}
function examinetipclose() {
	$("#examinetip").fadeOut(200);
}
layui.use('laydate', function() {
  var laydate = layui.laydate;
  laydate.render({
    elem: '#startTime'
    ,type: 'datetime'
  });
  laydate.render({
    elem: '#endTime'
    ,type: 'datetime'
  });
})
</script>
  <script>
    $(function (){
      load(1,5);
      $("#suborder").click(function (){
        window.event.returnValue=false;
        orderId= $("#orderId").val()
        customName= $("#customName").val()
        startTime= $("#startTime").val()
        endTime= $("#endTime").val()
        minMoney= $("#minMoney").val()
        maxMoney= $("#maxMoney").val()
        statu= $("#status").val()
        load(1,5,orderId,customName,startTime,endTime,minMoney,maxMoney,statu);
        if (minMoney!=null&&maxMoney!=null&&(minMoney>maxMoney)){

            layui.use('layer', function(){
              var layer = layui.layer;
              layer.msg("你很调皮，但是霸霸宠你！",{icon:1})
            });
        }
        // else {
        //   layui.use('layer', function(){
        //     var layer = layui.layer;
        //     layer.msg("查询成功！",{icon:1})
        //   });
        // }
        else if(startTime!=null&&endTime!=null&&(startTime>endTime)){
            layui.use('layer', function(){
              var layer = layui.layer;
              layer.msg("你很调皮，但是霸霸宠你！",{icon:1})
            });
        }else {
          layui.use('layer', function(){
            var layer = layui.layer;
            layer.msg("查询成功！",{icon:1})
          });
        }

      })
    })
    function formatNumber(number, decimals, dec_point, thousands_sep) {
        /*
        * 参数说明：
        * number：要格式化的数字
        * decimals：保留几位小数
        * dec_point：小数点符号
        * thousands_sep：千分位符号
        * */
        number = (number + '').replace(/[^0-9+-Ee.]/g, '');
        var n = !isFinite(+number) ? 0 : +number,

            prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
            sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
            dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
            s = '',
            toFixedFix = function (n, prec) {
                var k = Math.pow(10, prec);
                return '' + Math.floor(n * k) / k;
            };
        s = (prec ? toFixedFix(n, prec) : '' + Math.floor(n)).split('.');
        var re = /(-?\d+)(\d{3})/;
        while (re.test(s[0])) {
            s[0] = s[0].replace(re, "$1" + sep + "$2");
        }

        if ((s[1] || '').length < prec) {
            s[1] = s[1] || '';
            s[1] += new Array(prec - s[1].length + 1).join('0');
        }
        $("#Money").val(s.join(dec))
    }
    function load(currentpage,rows,orderId,customName,startTime,endTime,minMoney,maxMoney,statu){
      var url="http://121.37.227.40:8000/"
      axios({
        url:url+'marketing/marketingOrdersPage',
        method:"POST",
        data:{
        },
        params:{
          currentPage: currentpage,
          rows: rows,
          orderId:orderId,
          customName:customName,
          startTime:startTime,
          endTime:endTime,
          minMoney:minMoney,
          maxMoney:maxMoney,
          status:statu
        },
        dataType:"JSON"
      }).then(function (rel){
        rel = rel.data;
        let lis='<thead>\n' +
                '        <tr>\n' +
                '          <th>序号</th>\n' +
                '          <th>订单编号</th>\n' +
                '          <th>客户姓名</th>\n' +
                '          <th>联系电话</th>\n' +
                '          <th>订购时间</th>\n' +
                '          <th>金额</th>\n' +
                '          <th>操作人</th>\n' +
                '          <th>审核状态</th>\n' +
                '          <th>审核人</th>\n' +
                '          <th>审核时间</th>\n' +
                '          <th>操作</th>\n' +
                '        </tr>\n' +
                '      </thead>'
        lis+='<tbody>';
        let li
        for (var i=0;i<rel.resultData.list.length;i++){
          let data=rel.resultData.list[i];
          formatNumber(parseFloat(data.orderMoney),2,".",",")
          var money=$("#Money").val()
          let status=data.status;
          if(data.status==0){
            status = "未审核";
            li+='<tr>\n' +
                    '          <td>' + ((i + 1) +((currentpage-1)*rows))+ '</td>\n' +
                    '          <td>'+data.orderId +'</td>\n' +
                    '          <td>'+data.customName.customName +'</td>\n' +
                    '          <td>'+data.customName.telephone+'</td>\n' +
                    '          <td>'+data.orderTime+'</td>\n' +
                    '          <td>￥'+money+'</td>\n' +
                    '          <td>'+data.operator.uName +'</td>\n' +
                    '          <td>'+status+'</td>\n' +
                    '          <td></td>\n' +
                    '          <td></td>\n' +
                    '          <td>\n' +
                    '          \t<a href="javascript:void(0)" class="tablelink" onclick="orderView(\''+data.orderId +'\')">查看详情</a>\n' +
                    '            <a href="javascript:void(0)" class="tablelink" onclick="updateOrder(\''+data.orderId +'\')">修改</a>\n' +
                    '            <a href="javascript:void(0);" class="tablelink" onclick="deltipOpen(\''+data.orderId +'\','+currentpage+','+rows+')">删除</a>\n' +
                    '            <a href="javascript:void(0);" class="tablelink" onclick="examinetipOpen(\''+data.orderId +'\','+currentpage+','+rows+')">提交审核</a>\n' +
                    '            </td>\n' +
                    '        </tr>'
          }else if(data.status==1){
            status = "审核中";
            li+='<tr>\n' +
                    '          <td>' + ((i + 1) +((currentpage-1)*rows))+ '</td>\n' +
                    '          <td>'+data.orderId +'</td>\n' +
                    '          <td>'+data.customName.customName +'</td>\n' +
                    '          <td>'+data.customName.telephone+'</td>\n' +
                    '          <td>'+data.orderTime+'</td>\n' +
                    '          <td>￥'+money+'</td>\n' +
                    '          <td>'+data.operator.uName +'</td>\n' +
                    '          <td>'+status+'</td>\n' +
                    '          <td>'+data.checker.uName+'</td>\n' +
                    '          <td>'+ data.checkTime+'</td>\n' +
                    '          <td>\n' +
                    '          \t<a href="javascript:void(0)" class="tablelink" onclick="orderView(\''+data.orderId +'\')">查看详情</a>\n' +
                    '          </td>\n' +
                    '        </tr>'
          }else if (data.status==2){
            status = "审核通过";
            li+='<tr>\n' +
                    '          <td>' + ((i + 1) +((currentpage-1)*rows))+ '</td>\n' +
                    '          <td>'+data.orderId +'</td>\n' +
                    '          <td>'+data.customName.customName +'</td>\n' +
                    '          <td>'+data.customName.telephone+'</td>\n' +
                    '          <td>'+data.orderTime+'</td>\n' +
                    '          <td>￥'+money+'</td>\n' +
                    '          <td>'+data.operator.uName +'</td>\n' +
                    '          <td>'+status+'</td>\n' +
                    '          <td>'+data.checker.uName+'</td>\n' +
                    '          <td>'+ data.checkTime+'</td>\n' +
                    '          <td>\n' +
                    '          \t<a href="javascript:void(0)" class="tablelink" onclick="orderView(\''+data.orderId +'\')">查看详情</a>\n' +
                    '            <a href="javascript:void(0)" class="tablelink"  onclick="ckView(\''+data.orderId +'\')">出库详情</a>\n' +
                    '          </td>\n' +
                    '        </tr>'
          }else if (data.status==3){
            status = "审核不通过";
            li+='<tr>\n' +
                    '          <td>' + ((i + 1) +((currentpage-1)*rows))+ '</td>\n' +
                    '          <td>'+data.orderId +'</td>\n' +
                    '          <td>'+data.customName.customName +'</td>\n' +
                    '          <td>'+data.customName.telephone+'</td>\n' +
                    '          <td>'+data.orderTime+'</td>\n' +
                    '          <td>￥'+money+'</td>\n' +
                    '          <td>'+data.operator.uName +'</td>\n' +
                    '          <td>'+status+'</td>\n' +
                    '          <td>'+data.checker.uName+'</td>\n' +
                    '          <td>'+ data.checkTime+'</td>\n' +
                    '          <td>\n' +
                    '            <a href="javascript:void(0);" class="tablelink" onclick="updateOrder(\''+data.orderId +'\')">修改</a>\n' +
                    '            <a href="javascript:void(0);" class="tablelink" onclick="examinetipOpen()">提交审核</a>\n' +
                    '          </td>\n' +
                    '        </tr>'
          }
        }
        lis+=li;
        lis+='</tbody>';
        $(".tablelist").html(lis);
        $('.tablelist tbody tr:odd').addClass('odd');

        layui.use("laypage",function (){
          var laypage=layui.laypage;
          laypage.render({
            elem:"page",
            count:rel.resultData.totalCount,
            theme: '#eb5409',
            limit:rows,
            limits:[3,5,10],
            curr:currentpage,
            layout:['prev','page','next','limit','count','skip'],
            jump:function (obj,first){
              currentpage=obj.curr
              rows=obj.limit
              if (!first){
                load(currentpage,rows,orderId,customName,startTime,endTime,minMoney,maxMoney,statu)
              }
            }
          })
        })
      })
    }
    function orderView(orderId){
      location.href="../order/orderView.html?orderId="+orderId;
    }
    function ckView(orderId) {
      location.href="../../storage/delivery/deliveryView.html?orderId="+orderId
    }
    function updateOrder(orderId) {

      location.href="orderUpdate.html?orderId="+orderId
    }
  </script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>营销管理</li>
    <li>订购单管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <ul class="tools">
      <li> 订单编号:
        <input type="text" id="orderId"/>
      </li>
      <li> 客户姓名:
        <input type="text" id="customName"/>
      </li>
      <li> 订购时间:
        <input type="text" id="startTime" />-<input type="text" id="endTime" />
      </li>
      <li> 金额:
        <input type="text" class="stinput" id="minMoney"/>-<input type="text" class="stinput" id="maxMoney"/>
      </li>
      <li> 审核状态：
        <select id="status">
          <option value="99">请选择</option>
          <option value="0">未审核</option>
          <option value="1">审核中</option>
          <option value="2">审核通过</option>
          <option value="3">审核未通过</option>
        </select>
      </li>
      <li class="subBut" id="suborder"><img src="../../images/t06.png" />查询</li>
      <li class="subBut" onclick="window.location.href='orderAdd.html'"><img src="../../images/t01.png" />添加</li>
    </ul>
    <table class="tablelist">
<!--      <thead>-->
<!--        <tr>-->
<!--          <th>序号</th>-->
<!--          <th>订单编号</th>-->
<!--          <th>客户姓名</th>-->
<!--          <th>联系电话</th>-->
<!--          <th>订购时间</th>-->
<!--          <th>金额</th>-->
<!--          <th>操作人</th>-->
<!--          <th>审核状态</th>-->
<!--          <th>审核人</th>-->
<!--          <th>审核时间</th>-->
<!--          <th>操作</th>-->
<!--        </tr>-->
<!--      </thead>-->
<!--      <tbody>-->
<!--        <tr>-->
<!--          <td>1</td>-->
<!--          <td>DJ201701270001</td>-->
<!--          <td>王金平</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>2017-01-25 15:05:05</td>-->
<!--          <td>￥9,876,582</td>-->
<!--          <td>关羽</td>-->
<!--          <td>未审核</td>-->
<!--          <td></td>-->
<!--          <td></td>-->
<!--          <td>-->
<!--          	<a href="orderView.html" class="tablelink">查看详情</a>-->
<!--            <a href="orderUpdate.html" class="tablelink">修改</a>-->
<!--            <a href="javascript:void(0);" class="tablelink" onclick="deltipOpen()">删除</a>-->
<!--            <a href="javascript:void(0);" class="tablelink" onclick="examinetipOpen()">提交审核</a>-->
<!--            </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>2</td>-->
<!--          <td>DJ201701270002</td>-->
<!--          <td>张永祥</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>2017-01-25 15:05:05</td>-->
<!--          <td>￥9,876,582</td>-->
<!--          <td>关羽</td>-->
<!--          <td>审核中</td>-->
<!--          <td></td>-->
<!--          <td></td>-->
<!--          <td>-->
<!--          	<a href="orderView.html" class="tablelink">查看详情</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>3</td>-->
<!--          <td>DJ201701270003</td>-->
<!--          <td>王金平</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>2017-01-25 15:05:05</td>-->
<!--          <td>￥9,876,582</td>-->
<!--          <td>关羽</td>-->
<!--          <td>审核通过</td>-->
<!--          <td>曹操</td>-->
<!--          <td>2017-01-30 12:05:05</td>-->
<!--          <td>-->
<!--          	<a href="orderView.html" class="tablelink">查看详情</a>-->
<!--            <a href="../../storage/delivery/deliveryView.html" class="tablelink">出库详情</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>4</td>-->
<!--          <td>DJ201701270004</td>-->
<!--          <td>张永祥</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>2017-01-25 15:05:05</td>-->
<!--          <td>￥9,876,582</td>-->
<!--          <td>关羽</td>-->
<!--          <td>审核不通过</td>-->
<!--          <td>曹操</td>-->
<!--          <td>2017-01-30 12:05:05</td>-->
<!--          <td>-->
<!--            <a href="orderUpdate.html" class="tablelink">修改</a>-->
<!--            <a href="javascript:void(0);" class="tablelink" onclick="examinetipOpen()">提交审核</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--      </tbody>-->
    </table>
    <div class="pagin" id="page">
<!--      <div class="message">共<i class="blue">1256</i>条记录，当前显示第&nbsp;<i class="blue">2&nbsp;</i>页</div>-->
<!--      <ul class="paginList">-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">1</a></li>-->
<!--        <li class="paginItem current"><a href="javascript:;">2</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">3</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">4</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">5</a></li>-->
<!--        <li class="paginItem more"><a href="javascript:;">...</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">10</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
<!--      </ul>-->
    </div>
  </form>
  <!-- 删除提示框 -->
  <div id="deltip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="deltipClose()"></a></div>
    <div class="tipinfo"> <span><img src="../../images/ticon.png" /></span>
      <div class="tipright">
        <p>是否确认删除此条信息？</p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" id="delOrder" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="deltipClose()" />
    </div>
  </div>
  
  <!-- 审批提示框 -->
  <div id="examinetip" class="tip">
    <div class="tiptop">
    	<span>提示信息</span><a onclick="examinetipclose()"></a>
    </div>
    <div class="tipinfo1"> 
    	
        部门：
            <select class="dfselect" id="dept">
            	<option value="0">请选择</option>
                <option value="1">董事会</option>
                <option value="5">市场部</option>
            </select>
			<p/>
            职位：
            <select class="dfselect" id="post">
            	<option value="0">请选择</option>

            </select>
   			<p/>
            姓名：
            <select class="dfselect" id="name">
            	<option value="0">请选择</option>
            </select>
			<p/>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" id="subexamine" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="examinetipclose()" />
    </div>
  </div>
</div>
<div><input id="Money" style="display: none"></div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');

    $("#dept").change(function (){
        var s= document.getElementById("post")
        remove1(s)
        var deptId=$("#dept").val()
        if (deptId==0){
            var str='<option value="0">请选择</option>'
            $("#post").html(str)
        }else {
        var url="http://121.37.227.40:8000/"
        axios({
            url:url+'marketing/queryJob',
            method:"POST",
            data:{
            },
            params:{
                deptId:deptId
            },
            dataType:"JSON"
        }).then(function (rel){
            rel=rel.data;
            var str='<option value="0">请选择</option>'
            for (var i=0;i<rel.resultData.length;i++){
                var data=rel.resultData[i]
            if (data.jobId==3||data.jobId==4){
              continue;
            }
                str+='<option value="'+data.jobId +'">'+ data.jobName +'</option>'
            }
            $("#post").html(str)
        })
        }
    })

    $("#post").change(function (){
        var s= document.getElementById("name")
        remove1(s)
        var jobId=$("#post").val()
        if (jobId==0){
            var str='<option value="0">请选择</option>'
            $("#name").html(str)
        }else {
            var url="http://121.37.227.40:8000/"
            axios({
                url:url+'marketing/queryUser',
                method:"POST",
                data:{
                },
                params:{
                    jobId:jobId
                },
                dataType:"JSON"
            }).then(function (rel){
                rel=rel.data;
                var str='<option value="0">请选择</option>'
                for (var i=0;i<rel.resultData.length;i++){
                    var data=rel.resultData[i]
                    str+='<option value="'+data.uId +'">'+ data.uName +'</option>'
                }
                $("#name").html(str)
            })
        }
    })

    function remove1(s) {
        var options = s.getElementsByTagName("option");
        for(var i = 0; i < options.length; i++) {
            s.removeChild(options[i]);
            i--;
        }
    }
</script>
</body>
</html>
